package com.wsoft.portal.controller;

import com.wsoft.portal.query.org.member.OrgMemberInsertQuery;
import com.wsoft.portal.query.org.member.OrgMemberListQuery;
import com.wsoft.portal.query.org.member.OrgMemberUpdateQuery;
import com.wsoft.portal.service.IPortalOrgMemberService;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 空间类型 前端控制器
 * @author Z001
 * @since 2024年12月27日 10:01:32
 */
@RestController
@Tag(name = "主题单位/个人配置")
@RequestMapping("/portal/orgMember")
public class PortalOrgMemberController {

    @Resource
    private IPortalOrgMemberService orgMemberService;

    @Operation(summary = "新增单位/个人配置", description = "新增单位/个人配置")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid OrgMemberInsertQuery query) {
        boolean b = orgMemberService.insertOrgMember(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改单位/个人配置", description = "修改单位/个人配置")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid OrgMemberUpdateQuery query) {
        boolean b = orgMemberService.updateOrgMember(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "获取单位/个人配置详情", description = "获取单位/个人配置详情")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(orgMemberService.getOrgMember(id));
    }

    @Operation(summary = "删除单位/个人配置", description = "删除单位/个人配置")
    @GetMapping("/delete")
    public ResponseResult dropTheme(@RequestParam("id") Long id) {
        boolean b = orgMemberService.deleteOrgMember(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "查询列表", description = "查询列表")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody OrgMemberListQuery query) {
        return ResponseResult.success(ResponsePage.restPage(orgMemberService.listOrgMember(query)));
    }


}
